package thread;

import java.util.concurrent.*;

public class demo20 {
    public static void main(String[] args) {
        BlockingQueue<String> queue = new ArrayBlockingQueue<>(3);
        BlockingQueue<String> queue2;
        queue2 = new LinkedBlockingQueue<>();
        BlockingQueue<String> queue3 = new PriorityBlockingQueue<>();//基于优先级队链生成的阻塞队列

        Thread t1 = new Thread(() -> {
            try {
                queue.put("1");
                System.out.println("放入1");
                queue.put("2");
                System.out.println("放入2");
                queue.put("3");
                System.out.println("放入3");
                queue.put("4");
                System.out.println("放入4");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        });
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println("t2:" + queue.take());
                System.out.println("t2:" + queue.take());
                System.out.println("t2:" + queue.take());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        t1.start();
        t2.start();


    }


}
